package cn.me.alphamq.common.entity.req;

import cn.me.alphamq.common.entity.BaseMsg;
import cn.me.alphamq.common.entity.Message;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 重试消费消息的请求
 * <p>
 * 当消费者消费失败时，消费者需要让 broker 知道哪些消息没有消费
 *
 * @author f
 */
public class RetryConsumeMsgReq extends BaseMsg {

    /**
     * 消费的主题
     */
    private String topic;

    /**
     * 消费者组名
     */
    private String consumerGroup;

    /**
     * 消息所在队列的 id
     */
    private int queueId;

    /**
     * 消息的最大重试次数
     */
    private int maxRetryTimes;

    /**
     * 消费失败的消息，每个对象只含 {@code msgOffset} 和 {@code msgLength}
     */
    private List<Message> messageList;

    public RetryConsumeMsgReq() {
    }

    public RetryConsumeMsgReq(String topic, String consumerGroup, int queueId,
                              int maxRetryTimes, List<Message> messageList) {
        this.topic = topic;
        this.consumerGroup = consumerGroup;
        this.queueId = queueId;
        this.maxRetryTimes = maxRetryTimes;
        this.messageList = messageList.stream().map(Message::simplify).collect(Collectors.toList());
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getConsumerGroup() {
        return consumerGroup;
    }

    public void setConsumerGroup(String consumerGroup) {
        this.consumerGroup = consumerGroup;
    }

    public int getQueueId() {
        return queueId;
    }

    public void setQueueId(int queueId) {
        this.queueId = queueId;
    }

    public int getMaxRetryTimes() {
        return maxRetryTimes;
    }

    public void setMaxRetryTimes(int maxRetryTimes) {
        this.maxRetryTimes = maxRetryTimes;
    }

    public List<Message> getMessageList() {
        return messageList;
    }

    public void setMessageList(List<Message> messageList) {
        this.messageList = messageList;
    }
}
